'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, jwt } = app;

  router.post('/api/v1/login', controller.common.login);
  router.post('/api/v1/register', controller.common.register);

  /**
   * user
   */
  router.get('/api/v1/user/:id/info', jwt, controller.user.getUserInfo);
  router.put('/api/v1/user/info', jwt, controller.user.updateUserInfo);
  router.put('/api/v1/user/setting', jwt, controller.user.updateUserSetting);
  router.put('/api/v1/user/password', jwt, controller.user.updateUserPassword);
  router.get('/api/v1/user/sign', jwt, controller.user.getSign);
  router.post('/api/v1/user/sign', jwt, controller.user.sign);
  router.post('/api/v1/user/avatar/upload', jwt, controller.user.uploadPic);
  router.get('/api/v1/user/:id/essay/list', jwt, controller.user.searchUserEssayList);
  router.get('/api/v1/user/essay/like', jwt, controller.user.essayLike);
  router.get('/api/v1/user/essay/collect', jwt, controller.user.essayCollect);
  router.get('/api/v1/user/comment/like', jwt, controller.user.essayCommentLike);
  router.get('/api/v1/user/leetcode/collect', jwt, controller.user.lcCollect);
  router.get('/api/v1/user/topic', jwt, controller.user.getUserTopicList);
  router.get('/api/v1/user/leetcode/like', jwt, controller.user.lcLike);
  router.get('/api/v1/user/follow/list', jwt, controller.user.getFollowList);
  router.get('/api/v1/user/followed/list', jwt, controller.user.getFollowedList);
  router.get('/api/v1/user/:id/follow/list', jwt, controller.user.searchFollowList);
  router.get('/api/v1/user/:id/followed/list', jwt, controller.user.searchFollowedList);
  router.post('/api/v1/user/follow/:id', jwt, controller.user.followUser);
  router.delete('/api/v1/user/follow/:id', jwt, controller.user.cancelFollowTopic);

  /**
   * essay
   */
  router.get('/api/v1/user/:id/save/list', jwt, controller.essay.getSaveEssayList);
  router.get('/api/v1/essay/list', jwt, controller.essay.getEssayTabList);
  router.get('/api/v1/essay/list/:id', jwt, controller.essay.getEssayList);
  router.get('/api/v1/user/:id/essay/info', jwt, controller.essay.getUserEssayInfo);
  router.get('/api/v1/essay/:id', jwt, controller.essay.getEssayDetail);
  router.get('/api/v1/essay/:id/info', jwt, controller.essay.getEssayInfo);
  router.post('/api/v1/essay', jwt, controller.essay.addEssay);
  router.post('/api/v1/essay/save', jwt, controller.essay.addSaveEssay);
  router.delete('/api/v1/essay/save', jwt, controller.essay.deleteSaveEssay);
  router.post('/api/v1/essay/:id/like', jwt, controller.essay.likeEssay);
  router.delete('/api/v1/essay/:id/like', jwt, controller.essay.dislikeEssay);
  router.post('/api/v1/essay/:id/collect', jwt, controller.essay.collectEssay);
  router.delete('/api/v1/essay/:id/collect', jwt, controller.essay.notcollectEssay);

  /**
   * comment
   */
  router.get('/api/v1/essay/:id/comment/list', jwt, controller.comment.getCommentList);
  router.post('/api/v1/comment', jwt, controller.comment.addComment);
  router.delete('/api/v1/comment/:id', jwt, controller.comment.deleteComment);
  router.post('/api/v1/comment/:id/like', jwt, controller.comment.likeComment);
  router.delete('/api/v1/comment/:id/like', jwt, controller.comment.dislikeComment);

  /**
   * leetcode
   */
  router.get('/api/v1/leetcode/list', jwt, controller.leetcode.getLeetCodeList);
  router.get('/api/v1/user/:id/leetcode/info', jwt, controller.leetcode.getLeetCodeInfo);
  router.get('/api/v1/leetcode/:id/info', jwt, controller.leetcode.getLeetCodeUserInfo);
  router.post('/api/v1/leetcode/:id/like', jwt, controller.leetcode.liekLeetCode);
  router.delete('/api/v1/leetcode/:id/like', jwt, controller.leetcode.disliekLeetCode);
  router.post('/api/v1/leetcode/:id/collect', jwt, controller.leetcode.collectLeetCode);
  router.delete('/api/v1/leetcode/:id/collect', jwt, controller.leetcode.cancelCollectLeetCode);
  router.post('/api/v1/leetcode/:id/done', jwt, controller.leetcode.doneLeetCode);
  router.delete('/api/v1/leetcode/:id/done', jwt, controller.leetcode.cancelDoLeetCode);

  /**
   * topic
   */
  router.get('/api/v1/topic/list', jwt, controller.topic.getTopicCateList);
  router.get('/api/v1/topic/list/:id', jwt, controller.topic.getTopicList);
  router.get('/api/v1/topic/:id', jwt, controller.topic.getTopicDetail);
  router.post('/api/v1/topic', jwt, controller.topic.addTopic);
  router.get('/api/v1/topic/:id/comment/list', jwt, controller.topic.getTopicCommentList);
  router.post('/api/v1/topic/comment', jwt, controller.topic.addTopicComment);
  router.delete('/api/v1/topic/comment/:id', jwt, controller.topic.deleteTopicComment);
  router.post('/api/v1/topic/comment/:id/like', jwt, controller.topic.likeTopicComment);
  router.delete('/api/v1/topic/comment/:id/like', jwt, controller.topic.dislikeTopicComment);
};
